|
1
|
|
|
import { |
|
2
|
|
|
Controller, |
|
3
|
|
|
Inject, |
|
4
|
|
|
Post, |
|
5
|
|
|
Body, |
|
6
|
|
|
BadRequestException, |
|
7
|
|
|
UseGuards, |
|
8
|
|
|
Param |
|
9
|
|
|
} from '@nestjs/common'; |
|
10
|
|
|
import { AuthGuard } from '@nestjs/passport'; |
|
11
|
|
|
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger'; |
|
12
|
|
|
import { ICommandBus } from 'src/Application/ICommandBus'; |
|
13
|
|
|
import { CreateShootingCommand } from 'src/Application/School/Command/Shooting/CreateShootingCommand'; |
|
14
|
|
|
import { UserRole } from 'src/Domain/User/User.entity'; |
|
15
|
|
|
import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO'; |
|
16
|
|
|
import { Roles } from 'src/Infrastructure/User/Decorator/Roles'; |
|
17
|
|
|
import { RolesGuard } from 'src/Infrastructure/User/Security/RolesGuard'; |
|
18
|
|
|
import { ShootingDTO } from '../../DTO/ShootingDTO'; |
|
19
|
|
|
|
|
20
|
|
|
@Controller('schools') |
|
21
|
|
|
@ApiTags('School shooting') |
|
22
|
|
|
@ApiBearerAuth() |
|
23
|
|
|
@UseGuards(AuthGuard('bearer'), RolesGuard) |
|
24
|
|
|
export class CreateShootingAction { |
|
25
|
|
|
constructor( |
|
26
|
|
|
@Inject('ICommandBus') |
|
27
|
|
|
private readonly commandBus: ICommandBus |
|
28
|
|
|
) {} |
|
29
|
|
|
|
|
30
|
|
|
@Post(':id/shootings') |
|
31
|
|
|
@Roles(UserRole.PHOTOGRAPHER) |
|
32
|
|
|
@ApiOperation({ summary: 'Create a shooting' }) |
|
33
|
|
|
public async index(@Param() idDto: IdDTO, @Body() dto: ShootingDTO) { |
|
34
|
|
|
const { name, shootingDate, groupClosingDate, individualClosingDate, notice } = dto; |
|
35
|
|
|
|
|
36
|
|
|
try { |
|
37
|
|
|
const id = await this.commandBus.execute( |
|
38
|
|
|
new CreateShootingCommand( |
|
39
|
|
|
name, |
|
40
|
|
|
new Date(shootingDate), |
|
41
|
|
|
new Date(groupClosingDate), |
|
42
|
|
|
new Date(individualClosingDate), |
|
43
|
|
|
idDto.id, |
|
44
|
|
|
notice |
|
45
|
|
|
) |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
return { id }; |
|
49
|
|
|
} catch (e) { |
|
50
|
|
|
throw new BadRequestException(e.message); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|